
import Vue from 'vue'
import App from './App'
import router from './router'
import http from '../src/http/https'
import store from '../src/store/state.js'
import '../src/assets/icons/iconfont.css'

// ui框架
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';

// 百度地图定位
// import BaiduMap from 'vue-baidu-map'
// Vue.use(BaiduMap, {
//   /* 需要注册百度地图开发者来获取你的ak */
//   ak: 'T22BZ-H55WD-DUU4K-P3AUS-DWSTV-EKFDD'
// })

Vue.use(ElementUI);

// 兄弟传值

// axios添加全局prototype属性
Vue.prototype.$http = http;


// 解决点击跳转自己报错
import Router from 'vue-router'
const originalreplace = Router.prototype.replace
Router.prototype.replace = function replace(location) {
  return originalreplace.call(this, location).catch(err => err)
}

const originalPush = Router.prototype.push
Router.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
} 

// 路由守卫，未登录不可到个人中心，重定向到登录页
router.beforeEach((to, from, next) => {
  if (to.meta.login) {
    if (!window.sessionStorage.getItem('cookie-session')) {
      next({
        path: '/login'
      })
    }
    next()
  } else {
    next()
  }
})

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  store,
  components: { App },
  template: '<App/>'
})
